package org.example.service.impl;

import com.github.pagehelper.PageHelper;
import org.example.dao.ModelDao;
import org.example.domain.Model;
import org.example.domain.PageBean;
import org.example.service.ModuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Jimmy
 * @version 1.0
 */
@Service
public class ModuleServiceImpl implements ModuleService {

    @Autowired
    private ModelDao modelDao;

    @Override
    public PageBean<Model> findByPage(Model model, int pagenum, int pagesize) {
        PageHelper.startPage(pagenum, pagesize);
        List<Model> models = modelDao.findByPage(model);
        int total = modelDao.findTotal(model);
        return new PageBean<>(total,pagenum,models);
    }

    @Override
    public int addModule(Model model) {
        return modelDao.addModel(model);
    }

    @Override
    public Model findById(String modelId) {
        return modelDao.findByMid(modelId);
    }

    @Override
    public int update(Model model) {
        return modelDao.update(model);
    }

    @Override
    public int delete(String modelId) {
        return modelDao.delete(modelId);
    }
}
